<?php

namespace app\model;

use think\facade\Db;
use think\Model;

class StatisticsModel extends Model {

    protected $table ="statistics";

    protected $pk = 'id';

    private $redisModel;

    private $cacheKey="";


    public function __construct()
    {
        parent::__construct();

        $this->cacheKey = "statistics:".date("Ymd");

        $this->redisModel = new RedisModel();
    }


    /*
     * 获取pv
     * */
    public function getPv(){
        return $this->redisModel->get($this->cacheKey.":pv");
    }

    /*
   * pv
   * */
    public function pv(){
        return $this->redisModel->incr($this->cacheKey.":pv");
    }


    /*
 * 获取pv
 * */
    public function getUv(){
        return $this->redisModel->get($this->cacheKey.":uv");
    }

    /*
     * uv
     * */
    public function uv($id){
        if(!$this->redisModel->get($this->cacheKey.":uv:".$id)){
            $this->redisModel->set($this->cacheKey.":uv:".$id,1,86400);
            return $this->redisModel->incr($this->cacheKey.":uv");
        }
    }



    /*
     * 获取pv
     * */
    public function getTodayLogin(){
        return $this->redisModel->get($this->cacheKey.":login");
    }

    /*
     * 今日登陆数
     * */
    public function todayLogin(){
        return $this->redisModel->incr($this->cacheKey.":login");
    }


    /*
    * 获取pv
    * */
    public function getTodayRegister(){
        return $this->redisModel->get($this->cacheKey.":register");
    }


    /*
     * 今日注册数
     * */
    public function todayRegister(){
        return $this->redisModel->incr($this->cacheKey.":register");
    }


}